package controle;

import java.io.IOException;
import java.util.Vector;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.beanutils.BeanUtils;

import smile.Network;
import teste.SmileApp;

import modelo.Atividade;



import dataBase.AtividadeBD;


public class BNCreate extends HttpServlet {
    public void init(ServletConfig config) throws ServletException {
	super.init(config);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	executeServlet(request, response);
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	executeServlet(request, response);
    }

    public void executeServlet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	response.setContentType("text/html");
	HttpSession session = request.getSession(true);

	Network net = new Network();
	
	// Creating node "Success" and setting/adding outcomes:
	net.addNode(Network.NodeType.Cpt, "Success");
	net.setOutcomeId("Success", 0, "Success");
	net.setOutcomeId("Success", 1, "Failure");
	
	// Creating node "Forecast" and setting/adding outcomes:
	net.addNode(Network.NodeType.Cpt, "Forecast");
	net.addOutcome("Forecast", "Good");
	net.addOutcome("Forecast", "Moderate");
	net.addOutcome("Forecast", "Poor");
	net.deleteOutcome("Forecast", 0);
	net.deleteOutcome("Forecast", 0);
	
	// Adding an arc from "Success" to "Forecast":
	net.addArc("Success", "Forecast");
	
	// Filling in the conditional distribution for node "Success". The 
	// probabilities are:
	// P("Success" = Success) = 0.2
	// P("Success" = Failure) = 0.8
	double[] aSuccessDef = {0.2, 0.8}; 
	net.setNodeDefinition("Success", aSuccessDef);



	    request.setAttribute("BN", null);

	    //getServletContext().getRequestDispatcher("/bn.jsp").forward(request, response);

	

    }

}
